from bson import ObjectId
from pydantic import Field, field_validator
from typing_extensions import Literal

from common.pydantic_base_model import BaseModel


class LeetCodeQuestionSchema(BaseModel):
    lc_sn: str  # leet_code 题目序号
    title: str  # 题目
    description: str  # 题目内容
    level: str = Literal['easy', 'medium', 'hard']
    tags: str


class UpdateQuestionSchema(BaseModel):
    id: str
    description: str  # 题目内容
    level: str = Literal['easy', 'medium', 'hard']
    tags: str
    solutions: str
    note: str  # 笔记

    @classmethod
    @field_validator('id')
    def validate_id(cls, v):
        if isinstance(v, str):
            return ObjectId(v)
        return v


class DeleteQuestionSchema(BaseModel):
    id: str
